How do I omit / filter / disgard repeated attribute information?

I have a module I use for reporting. That module is constructed as an index of the other modules in our database, with each object used to represent each corresponding module.

I have a view that includes a column to look through information in an associated module. We'll say the index module is module A and the associated module is module B. My script looks through the objects in module B to find links and sends back to module A the names of the modules (modules C, D, E, etc) linked in each object in module B.

My question regards trimming this information. I get repeated names in my column and want to omit them. For example, the column shows:
ModD
ModD
ModF
ModE
ModD
ModF
ModE
ModE
ModG
ModD

How can I make the column show simply:
ModD
ModE
ModF
ModG

?

I have no hang of Skips, so if that's the answer, I may need a pretty detailed explanation. I've been looking through the reference guide for a while now and cannot seem to come to a nice solution on my own.

Thanks so much in advance; this forum continues to save me time and time again.

S
SamIrons - Tue Sep 04 11:00:13 EDT 2012

Re: How do I omit / filter / disgard repeated attribute information?
Mathias Mamsch - Tue Sep 04 11:51:41 EDT 2012

Well the answer is indeed skip lists. You can read a bit about skips in the DXL help to get a more firm understanding, the major behaviour is, that they store key/value pairs, where the keys must be unique. So for one key, you can only have one value in a skip. So the idea to remove redundancy in your output is, to add each line to a skip, before putting it to the result. If the order of the item is important, you will only use the skip for checking if the line is already in the result.

// global variables to store the result
Buffer bufResult = create() 
Skip skLines = createString()  // when the skip stores string keys, then use 'createString' to create it
 
void clearResult () {
   bufResult = ""
   setempty skLines
}
 
void addToResult (string s) {
    // if the item is already in the skip, do not add again
    if (find(skLines, s)) return 
    if (length bufResult > 0) bufResult += "\n"
    bufResult += s
    // add the item to the skip
    put (skLines, s, 0)
}
 
addToResult ("Hello!")
addToResult ("World!")
addToResult ("Hello!")
addToResult ("(and Skips!)")
 
print stringOf bufResult

Since Skips have the nice property of sorting alphabetically you can also just put stuff to the Skip and later read it back from there:

// global variables to store the result
Skip skLines = createString()  // when the skip stores string keys, then use 'createString' to create it
 
void clearResult () {
   setempty skLines
}
 
Buffer getResult () {
    Buffer buf = create(); 
    // get the items sorted from the skip
    string s; for s in skLines do {
      if (length buf > 0) buf += "\n"
      buf += s
    }
    return buf
}
 
void addToResult (string s) {
    // if the item is already in the skip, do not add again
    if (find(skLines, s)) return 
    // add the item to the skip
    put (skLines, s, s)
}
 
addToResult ("Hello!")
addToResult ("World!")
addToResult ("Hello!")
addToResult ("(and Skips!)")
 
print stringOf getResult()

Note how in both example the duplicate item 'Hello!' is filtered from the result. Hope that helps, Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: How do I omit / filter / disgard repeated attribute information?
SamIrons - Tue Sep 04 13:09:25 EDT 2012

This works beautifully.

Re: How do I omit / filter / disgard repeated attribute information?
SamIrons - Tue Sep 04 13:10:24 EDT 2012

Mathias Mamsch - Tue Sep 04 11:51:41 EDT 2012

Well the answer is indeed skip lists. You can read a bit about skips in the DXL help to get a more firm understanding, the major behaviour is, that they store key/value pairs, where the keys must be unique. So for one key, you can only have one value in a skip. So the idea to remove redundancy in your output is, to add each line to a skip, before putting it to the result. If the order of the item is important, you will only use the skip for checking if the line is already in the result.

// global variables to store the result
Buffer bufResult = create() 
Skip skLines = createString()  // when the skip stores string keys, then use 'createString' to create it
 
void clearResult () {
   bufResult = ""
   setempty skLines
}
 
void addToResult (string s) {
    // if the item is already in the skip, do not add again
    if (find(skLines, s)) return 
    if (length bufResult > 0) bufResult += "\n"
    bufResult += s
    // add the item to the skip
    put (skLines, s, 0)
}
 
addToResult ("Hello!")
addToResult ("World!")
addToResult ("Hello!")
addToResult ("(and Skips!)")
 
print stringOf bufResult

Since Skips have the nice property of sorting alphabetically you can also just put stuff to the Skip and later read it back from there:

// global variables to store the result
Skip skLines = createString()  // when the skip stores string keys, then use 'createString' to create it
 
void clearResult () {
   setempty skLines
}
 
Buffer getResult () {
    Buffer buf = create(); 
    // get the items sorted from the skip
    string s; for s in skLines do {
      if (length buf > 0) buf += "\n"
      buf += s
    }
    return buf
}
 
void addToResult (string s) {
    // if the item is already in the skip, do not add again
    if (find(skLines, s)) return 
    // add the item to the skip
    put (skLines, s, s)
}
 
addToResult ("Hello!")
addToResult ("World!")
addToResult ("Hello!")
addToResult ("(and Skips!)")
 
print stringOf getResult()

Note how in both example the duplicate item 'Hello!' is filtered from the result. Hope that helps, Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Mathias,

Once again you've dazzled me. I truly appreciate it. And adding the new line to address my formatting. It's almost too much. Thanks again!